import request from './request';
import qs from 'qs';
// qs库 可以将对象转换成query想要的字符串格式，也可以将字符串转换成对象
// 封装的登录接口
export const LoginApi = (data: LoginParams): PromiseResData<LoginResData> =>
  request.post('/admin/login', data);
// 获取当前用户登录信息api
export const GetInfoApi = (): PromiseResData<InfoResData> =>
  request.get('/admin/info');
// 根据用户名或姓名分页获取用户列表api
export const GetAdminListApi = (
  params: AdminListParams
): PromiseResData<AdminListRes> => request.get('/admin/list', { params });
// 修改账号状态api
export const UpdateStatusApi = (
  params: UpdateStatus
): PromiseResData<UpdateStatusData> =>
  request.post(
    `/admin/updateStatus/${params.id}?status=${params.status}`,
    params
  );
// 获取指定用户信息api
export const GetAppointUserApi = (
  params: GetAppointUser
): PromiseResData<AdminListRes> => request.get(`/admin/list`, { params });
// 修改角色api
export const updateRoleApi = (
  data: updateRoleType
): PromiseResData<UpdateStatusData> =>
  request.post(`/admin/role/update`, qs.stringify(data));
// 修改角色api 第二种写法 post 里面是有第三个参数，是query参数
export const updateRoleApi2 = (
  data: updateRoleType
): PromiseResData<UpdateStatusData> =>
  request.post(`/admin/role/update`, null, { params: data });

// 修改指定用户信息
export const adminUpdateApi = (
  id: number,
  params: adminUpdateParams
): PromiseResData<UpdateStatusData> =>
  request.post(`/admin/update/${id}`, params);
// 获取所有角色api
export const GetRoleAllApi = (): PromiseResData<GetRoleAllData[]> =>
  request.get('/role/listAll');
// 获取指定用户的角色
export const GetAppointRoleApi = (
  adminId: number
): PromiseResData<GetRoleAllData[]> => request.get('/admin/role/' + adminId);
// 添加角色api
export const CreateRoleApi = (
  data: CreateRoleParams
): PromiseResData<UpdateStatusData> => request.post('/admin/register', data);
// 获取所有角色api
export const GetRoleListAllApi = (): PromiseResData<[]> =>
  request.get('/role/listAll');
// 根据角色名称获取角色列表
export const GetRoleListApi = (
  params: GetRoleListParams
): PromiseResData<GetRoleListData> => request.get('/role/list', { params });
// 查询商品
export const GetProductListApi = (
  params: GetProductListParams
): PromiseResData<GetRoleListData> => request.get('/product/list', { params });
// 请求首页数据
export const GetAdminDataApi = (): PromiseResData<GetAdminDataType> =>
  request.get('http://kumanxuan1.f3322.net:8360/admin/stat');
